import http from '@/utils/request.ts'
import type { DocumentFavorite, DocumentFavoriteRequest } from '@/modules/doc/types/doc.ts'

export const documentFavoriteApi = {
  // 添加收藏
  addFavorite: async (request: DocumentFavoriteRequest): Promise<DocumentFavorite> => {
    const response = await http.post<DocumentFavorite>('/document/favorite', request)
    return response.data
  },

  // 取消收藏
  removeFavorite: async (documentId: string): Promise<void> => {
    await http.delete(`/document/favorite/${documentId}`)
  },

  // 获取收藏列表
  getAllFavorites: async (): Promise<DocumentFavorite[]> => {
    const response = await http.get<DocumentFavorite[]>('/document/favorite')
    return response.data || []
  },

  // 检查文档是否已收藏
  isFavorited: async (documentId: string): Promise<boolean> => {
    const response = await http.get<boolean>(`/document/favorite/check/${documentId}`)
    return response.data
  }
}